
//静态内部类 (Static Inner Class Holder) 方式: 这是最推荐的懒汉 Singleton 实现方式，既保证了线程安全，又实现了懒加载
class SingletonLazyHolder {
    private SingletonLazyHolder() {}

    public static SingletonLazyHolder getInstance() {
        return InstanceHolder.instance;
    }

    private static class InstanceHolder {
        private static final SingletonLazyHolder instance = new SingletonLazyHolder();
    }
}

public class Demo18 {
    public static void main(String[] args) {
        SingletonLazyHolder singletonLazyHolder1 = SingletonLazyHolder.getInstance();
        SingletonLazyHolder singletonLazyHolder2 = SingletonLazyHolder.getInstance();

        if (singletonLazyHolder1 == singletonLazyHolder2) {
            System.out.println("同一个instance对象");
        }
    }
}
